import React, { Component } from 'react';
import { Form,Input,Button,notification ,Select } from 'antd'
import { addAdminL } from '@/service/people';
import { history } from 'umi'


const { Option } = Select
const formItemLayout = {
    labelCol: { span: 6 },
    wrapperCol: { span: 14 },
  };
const onFinish = (values: any) => {
    const { adminname, password, role } = values
    addAdminL({ adminname, password, role, checkedKeys:[] }).then((res) => {
      if(res.code === '10004'){
        notification.open({
            message: '吴奇霞为您提示呦',
            description:
              '账户名已存在，请更改账户名',
            // onClick: () => {
            //   console.log('Notification Clicked!');
            // },
        });
        const inputs = document.getElementsByTagName('INPUT')
        // console.log(inputs);
        for (let index = 0; index < inputs.length; index++) {
            inputs[index].value = ''
        }
        return
      } else {
        history.push('/people/admin')
      }
    })
};


class addAdmin extends Component {
    

    render() {

        return (
          <>
            <div>
            <Form
              name="validate_other"
              {...formItemLayout}
              onFinish={onFinish}
              initialValues={{
                  'adminname': '',
                  'password': '',
                  'role': ''
              }}
              >
              <Form.Item label="Plain Text">
                <span className="ant-form-text">添加管理员</span>
              </Form.Item>
              <Form.Item
                name="adminname"
                label="adminname"
                required
              >
                <Input size="large" placeholder="请输入管理员名称" />
              </Form.Item>
              <Form.Item
                name="password"
                label="password"
                required
              >
                <Input size="large" placeholder="请输入密码" />
              </Form.Item>
              <Form.Item
                name="role"
                label="role"
                required
              >
                <Select defaultValue="管理员" style={{ width: 120 }} allowClear>
                <Option value="1">管理员</Option>
                <Option value="2">超级管理员</Option>
              </Select>
              </Form.Item>
              <Form.Item wrapperCol={{ span: 12, offset: 6 }}>
                <Button type="primary" htmlType="submit">
                  Submit
                </Button>
              </Form.Item>
            </Form>
            </div>
          </>
            
        );
    }
}

export default addAdmin;